﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Input;
using System.Windows;
using PwdMgr.PwdMgrService.UserAuthentication;
using PwdMgr.Utility;
using PwdMgr.Utility.Crypto;
using PwdMgrUI.Objects;
using System.Resources;
using PwdMgrUI.Resource;
using System.Threading;

namespace PwdMgrUI.ViewModels
{
    internal class LoginViewModel : ViewModelBase
    {
        private IAuth _authService;
        public LoginViewModel()
            : base()
        {
            _authService = AuthFactory.CreateInstance();
        }

        private string _username;
        public string Username
        {
            get { return _username; }
            set
            {
                _username = value;
                OnPropertyChanged("Username");
            }
        }

        private Func<string> _getPassword = () =>
        {
            throw new NotImplementedException();
        };

        private Action<string> _setPassword = s =>
        {
            throw new NotImplementedException();
        };
        public Func<string> GetPassword
        {
            get { return _getPassword; }
            set { _getPassword = value; }
        }
        public Action<string> SetPassword 
        {
            get { return _setPassword; }
            set { _setPassword = value; }
        }

        public string Password
        {
            get
            {
                return GetPassword();
            }
            set
            {
                SetPassword(value);
                OnPropertyChanged("Password");
            }
        }

        public const string OKCommandID = "OK";
        [Command("OKExecute")]
        public ICommand OKCommand
        {
            get;
            protected set;
        }

        private void OKExecute(object parameter)
        {
        }

        private bool CheckValidate(IDictionary<CommandError, string> errors)
        {
            bool validate = true;

            if (string.IsNullOrEmpty(Username))
            {
                errors.Add(CommandError.InvalidateUsername,
                    "InvalidateUsername".I18N());
            }

            return validate;
        }
    }
}
